Crate jxl_oxide

source ·
Expand description

jxl-oxide is a JPEG XL decoder written in pure Rust. It’s internally organized into a few small crates. This crate acts as a blanket and provides a simple interface made from those crates to decode the actual image.

Decoding an image

Decoding a JPEG XL image starts with constructing JxlImage. If you’re reading a file, you can use JxlImage::open:

let image = JxlImage::open("input.jxl").expect("Failed to read image header");
println!("{:?}", image.image_header()); // Prints the image header

Or, if you’re reading from a reader that implements Read, you can use JxlImage::from_reader:

let image = JxlImage::from_reader(reader).expect("Failed to read image header");
println!("{:?}", image.image_header()); // Prints the image header

In async context, you’ll probably want to feed byte buffers directly. In this case, create an image struct with uninitialized state using JxlImage::new_uninit, and call feed_bytes and try_init:

let mut uninit_image = JxlImage::new_uninit();
let image = loop {
    uninit_image.feed_bytes(reader.read().await?);
    match uninit_image.try_init()? {
        InitializeResult::NeedMoreData(uninit) => {
            uninit_image = uninit;
        }
        InitializeResult::Initialized(image) => {
            break image;
        }
    }
};
println!("{:?}", image.image_header()); // Prints the image header

JxlImage parses the image header and embedded ICC profile (if there’s any). Use JxlImage::render_frame to render the image.

use jxl_oxide::{JxlImage, RenderResult};

for keyframe_idx in 0..image.num_loaded_keyframes() {
    let render = image.render_frame(keyframe_idx)?;
    present_image(render);
}

You might need to use JxlImage::rendered_icc to do color management correctly.

Re-exports

Modules

Structs

Enums

Type Aliases